<?php


namespace app\common\model;


use think\facade\Db;
use think\Model;

class Withdrawal extends Model
{
    /***    提现列表
     * @param array $where
     * @param $pageIndex
     * @param $pageSize
     * @return \think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function withdrawalList(array $where,$pageIndex,$pageSize){
        return self::where($where)->order('id desc')->page($pageIndex,$pageSize)->select();
    }

    /*** 提现详情
     * @param $where
     * @return array|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function withdrawalView($where){
        return self::where($where)->find();
    }

    /** 获取提现列表总条数
     * @param array $where
     * @return int
     */
    public static function withdrawalCount(array $where){
        return self::where($where)->count();
    }

    /*** 提现记录增加
     * @param array $data
     * @return Withdrawal|Model
     */
    public static function withdrawalAdd(array $data){
        return self::create($data);
    }

    /*** 获取总提现金额   state0待审 1通过 2拒绝
     * @param $where
     * @return int
     */
    public static function withdrawalBalanceCount($where){
        return self::where($where)->sum('withdrawal');
    }
    
    
    /**
     * 提现记录查找
     * @param array $where
     */
    public static function withdrawalQuery(array $where){
        return self::where($where)->find();
    }
    
    /***    提现修改 编辑
     * @param $where
     * @param $data
     * @return Activity
     */
    public static function withdrawalEdit($where,$data){
        return self::update($data,$where);
    }
}